//
//  SEGActivityListManager.m
//  Commom
//
//  Created by Clavis on 2019/9/16.
//

#import "SEGActivityListManager.h"

@implementation SEGActivityListManager

/**
 邻里社区展示活动菜单数据
 @param finished finished
 */
- (void)requestMenuActivityListWithFinished:(SEGNetworkReponse)finished
{
    //是否查询我参与的活动1:是2:否
    NSString *isMineString = @"2";
    SEGProfileModel *profile = [SEGProfileManager sharedManager].profile;
    NSDictionary* params = @{
                               @"userId" : kAccountUserID,
                               @"communityId" : kAccountCommunityID,
                               @"provinceId" : ValueToString(profile.provinceId),
                               @"cityId" : ValueToString(profile.cityId),
                               @"region" : ValueToString(profile.regionId),
                               @"isMine" : isMineString,
                               @"pageNo" : @(1)
                               };
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/act-api/activityInfo/queryActivitys.json",nil];
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST
                                            URLString:urlString
                                           parameters:params
                                             finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage){
                                                 if (isSuccessed) {
                                                     NSDictionary* dicData = [result valueForKey:@"data"];
                                                     if ((!dicData) || (![dicData isKindOfClass:[NSDictionary class]])) {
                                                         finished(NO, result, codeType, errorMessage);
                                                         return;
                                                     }
                                                     
                                                     NSArray* list = [dicData valueForKey:@"list"];
                                                     if (!list || ![list isKindOfClass:[NSArray class]]) {
                                                         finished(NO, result, codeType, errorMessage);
                                                         return;
                                                     }
                                                     
                                                     // 菜单是展示两条数据
                                                     NSMutableArray* modelArray = [NSMutableArray arrayWithCapacity:list.count];
                                                     [list enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL * _Nonnull stop) {
                                                         SEGActivityListModel* _model = [SEGActivityListModel initWithDictionary:dic];
                                                         [modelArray addObject:_model];
                                                         if (idx == 1) {
                                                             *stop = YES;
                                                         }
                                                     }];
                                                     
                                                     finished(YES, modelArray, codeType, errorMessage);
                                                 } else {
                                                     finished(NO, result, codeType, errorMessage);
                                                 }
                                             }];
}

@end
